<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片转SVG工具</title>
    <link rel="stylesheet" href="../coding/common.css">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet">
    <style>
        /* 基础样式和变量 */
        :root {
            --primary-color: #4a6fa5;
            --secondary-color: #6c8ebd;
            --background-color: #f5f7fa;
            --card-background: #ffffff;
            --text-color: #333333;
            --border-color: #e0e0e0;
            --error-color: #e74c3c;
            --success-color: #2ecc71;
            --shadow-color: rgba(0, 0, 0, 0.1);
            --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            --tip-background: #e3f2fd;
        }

        /* 暗黑模式变量 */
        [data-theme="dark"] {
            --primary-color: #5b8ad6;
            --secondary-color: #7fa3d7;
            --background-color: #1a1a2e;
            --card-background: #222438;
            --text-color: #e0e0e0;
            --border-color: #444444;
            --shadow-color: rgba(0, 0, 0, 0.3);
            --tip-background: #1a2a3a;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: var(--font-family);
            background-color: var(--background-color);
            color: var(--text-color);
            line-height: 1.6;
            transition: background-color 0.3s, color 0.3s;
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
            padding: 20px;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        /* 头部样式 */
        header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            padding-bottom: 15px;
            border-bottom: 1px solid var(--border-color);
        }

        header h1 {
            font-size: 2rem;
            color: var(--primary-color);
        }

        /* 头部控件区域 */
        .header-controls {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        /* 分享按钮 */
        .share-button {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 2px 6px;
            background-color: var(--secondary-color);
            color: white;
            border-radius: 15px;
            cursor: pointer;
            font-size: 14px;
            transition: background-color 0.3s, transform 0.1s;
        }

        .share-button:hover {
            background-color: var(--primary-color);
        }

        .share-button:active {
            transform: scale(0.98);
        }

        .share-button i {
            font-size: 16px;
        }

        /* 主题切换开关 */
        .theme-toggle {
            position: relative;
        }

        .theme-switch {
            opacity: 0;
            position: absolute;
        }

        .theme-switch-label {
            display: flex;
            align-items: center;
            justify-content: space-between;
            cursor: pointer;
            width: 50px;
            height: 26px;
            background-color: #83d8ff;
            border-radius: 100px;
            position: relative;
            transition: background-color 0.3s;
            padding: 0 5px;
        }

        .theme-switch:checked + .theme-switch-label {
            background-color: #4a4e69;
        }

        .theme-switch-label .fa-sun {
            color: #f39c12;
        }

        .theme-switch-label .fa-moon {
            color: #f1c40f;
        }

        .theme-switch-label .slider {
            position: absolute;
            width: 22px;
            height: 22px;
            border-radius: 50%;
            transition: 0.3s;
            background-color: white;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
            left: 2px;
        }

        .theme-switch:checked + .theme-switch-label .slider {
            transform: translateX(24px);
        }

        /* 隐私提示框样式 */
        .privacy-notice {
            margin-bottom: 20px;
            animation: fadeIn 0.5s ease-in-out;
        }

        .privacy-notice-content {
            display: flex;
            align-items: center;
            background-color: var(--tip-background);
            border-left: 4px solid #2196f3;
            padding: 15px;
            border-radius: 4px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            position: relative;
        }

        .privacy-notice-content i.fa-shield-alt {
            font-size: 20px;
            color: #2196f3;
            margin-right: 15px;
        }

        .privacy-notice-content p {
            flex: 1;
            margin: 0;
            font-size: 14px;
            color: var(--text-color);
        }

        .close-notice {
            background: none;
            border: none;
            color: #90a4ae;
            cursor: pointer;
            font-size: 16px;
            padding: 5px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: color 0.2s;
        }

        .close-notice:hover {
            color: #546e7a;
            background: none;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(-10px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        /* 主内容区域 */
        main {
            flex: 1;
            display: flex;
            gap: 20px;
        }

        .main-content {
            flex: 2;
            display: flex;
            flex-direction: column;
            gap: 20px;
        }

        .sidebar {
            flex: 1;
            max-width: 300px;
        }

        /* 侧边栏样式 */
        .sidebar-section {
            background-color: var(--card-background);
            border-radius: 8px;
            box-shadow: 0 4px 6px var(--shadow-color);
            padding: 20px;
            margin-bottom: 20px;
            transition: background-color 0.3s, box-shadow 0.3s;
        }

        .sidebar-section h3 {
            margin-bottom: 15px;
            color: var(--primary-color);
            font-size: 1.1rem;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .tool-links {
            list-style: none;
        }

        .tool-links a {
            display: flex;
            align-items: center;
            gap: 8px;
            color: var(--text-color);
            text-decoration: none;
            padding: 8px 12px;
            border-radius: 4px;
            transition: background-color 0.3s, color 0.3s;
        }

        .tool-links a:hover {
            background-color: var(--tip-background);
            color: var(--primary-color);
        }

        .ad-placeholder {
            background: linear-gradient(45deg, #f0f0f0, #e0e0e0);
            border: 2px dashed #ccc;
            border-radius: 8px;
            padding: 40px 20px;
            text-align: center;
            color: #999;
            font-style: italic;
        }

        [data-theme="dark"] .ad-placeholder {
            background: linear-gradient(45deg, #333, #444);
            border-color: #555;
            color: #777;
        }

        .config-panel {
            background-color: var(--card-background);
            border-radius: 8px;
            box-shadow: 0 4px 6px var(--shadow-color);
            padding: 20px;
        }

        .config-panel h2 {
            margin-bottom: 20px;
            color: var(--primary-color);
            display: flex;
            align-items: center;
            gap: 10px;
            font-size: 1.2rem;
        }

        /* 上传区域样式 */
        .upload-area {
            border: 2px dashed var(--border-color);
            border-radius: 8px;
            padding: 40px;
            text-align: center;
            background-color: var(--tip-background);
            transition: border-color 0.3s, background-color 0.3s;
            cursor: pointer;
            margin-bottom: 20px;
        }

        .upload-area:hover {
            border-color: var(--primary-color);
        }

        .upload-area.dragover {
            border-color: var(--primary-color);
            background-color: var(--primary-color);
            opacity: 0.1;
        }

        .upload-area i {
            font-size: 48px;
            color: var(--primary-color);
            margin-bottom: 15px;
        }

        .upload-area p {
            font-size: 16px;
            color: var(--text-color);
            margin-bottom: 10px;
        }

        .upload-area .file-info {
            font-size: 14px;
            color: var(--secondary-color);
        }

        #file-input {
            display: none;
        }

        /* 图片预览区域 */
        .preview-area {
            margin-bottom: 20px;
            display: none;
        }

        .preview-container {
            border: 1px solid var(--border-color);
            border-radius: 8px;
            padding: 20px;
            background-color: var(--card-background);
            text-align: center;
        }

        .preview-image {
            max-width: 600px;
            max-height: 300px;
            border-radius: 4px;
            box-shadow: 0 2px 8px var(--shadow-color);
        }

        .image-info {
            margin-top: 15px;
            font-size: 14px;
            color: var(--text-color);
        }

        /* 配置选项区域 */
        .config-options {
            margin-bottom: 20px;
        }

        .config-group {
            margin-bottom: 15px;
        }

        .config-group label {
            display: block;
            font-weight: 500;
            color: var(--text-color);
            margin-bottom: 5px;
        }

        .config-group input,
        .config-group select {
            width: 100%;
            padding: 10px;
            border: 1px solid var(--border-color);
            border-radius: 4px;
            background-color: var(--card-background);
            color: var(--text-color);
            font-size: 14px;
            transition: border-color 0.3s;
        }

        .config-group input:focus,
        .config-group select:focus {
            outline: none;
            border-color: var(--primary-color);
        }

        /* 按钮样式 */
        .button-group {
            display: flex;
            gap: 15px;
            justify-content: center;
            margin: 20px 0;
        }

        .btn {
            padding: 15px 30px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            font-weight: 500;
            display: inline-flex;
            align-items: center;
            gap: 10px;
            transition: background-color 0.3s, transform 0.1s;
        }

        .btn:hover {
            transform: scale(1.02);
        }

        .btn:active {
            transform: scale(0.98);
        }

        .btn-primary {
            background-color: var(--primary-color);
            color: white;
        }

        .btn-primary:hover {
            background-color: var(--secondary-color);
        }

        .btn-success {
            background-color: var(--success-color);
            color: white;
        }

        .btn-success:hover {
            background-color: #27ae60;
        }

        .btn:disabled {
            opacity: 0.6;
            cursor: not-allowed;
            transform: none;
        }

        /* 结果显示区域 */
        .result-panel {
            background-color: var(--card-background);
            border-radius: 8px;
            box-shadow: 0 4px 6px var(--shadow-color);
            padding: 20px;
            display: none;
        }

        .result-panel h2 {
            margin-bottom: 15px;
            color: var(--primary-color);
            display: flex;
            align-items: center;
            gap: 10px;
            font-size: 1.2rem;
        }

        .svg-preview {
            border: 1px solid var(--border-color);
            border-radius: 4px;
            padding: 20px;
            background-color: var(--tip-background);
            margin-bottom: 15px;
            text-align: center;
            min-height: 200px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .svg-code {
            width: 100%;
            height: 200px;
            padding: 15px;
            border: 1px solid var(--border-color);
            border-radius: 4px;
            background-color: var(--tip-background);
            color: var(--text-color);
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            font-size: 12px;
            line-height: 1.5;
            resize: vertical;
            transition: border-color 0.3s;
        }

        .svg-code:focus {
            outline: none;
            border-color: var(--primary-color);
        }

        /* 通知样式 */
        .notification {
            position: fixed;
            bottom: 20px;
            right: 20px;
            background-color: var(--success-color);
            color: white;
            padding: 10px 20px;
            border-radius: 4px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
            transform: translateY(100px);
            opacity: 0;
            transition: transform 0.3s, opacity 0.3s;
        }

        .notification.show {
            transform: translateY(0);
            opacity: 1;
        }

        .notification.error {
            background-color: var(--error-color);
        }

        /* 加载动画 */
        .loading {
            display: none;
            text-align: center;
            padding: 20px;
        }

        .loading i {
            font-size: 24px;
            color: var(--primary-color);
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .privacy-notice-content {
                flex-direction: column;
                text-align: center;
                padding: 15px 10px;
            }
            
            .privacy-notice-content i.fa-shield-alt {
                margin-right: 0;
                margin-bottom: 10px;
            }
            
            .close-notice {
                position: absolute;
                top: 5px;
                right: 5px;
            }

            header {
                flex-direction: column;
                gap: 15px;
                text-align: center;
            }

            main {
                flex-direction: column;
            }

            .sidebar {
                max-width: none;
            }

            .button-group {
                flex-direction: column;
            }
        }
    </style>
</head>
<body>
    <header>
        <div class="header-container">
            <div class="header-left">
                <div class="logo">
                    <span><a href="https://geekdaxue.co/" target="_blank"><img src="https://geekdaxue.co/static/images/logo_platypus.png" height="30px"></a></span>
                </div>
                <nav class="main-navigation">
                    <div class="nav-item dropdown">
                        <a href="#" class="nav-link">
                            JSON工具 <i class="fas fa-chevron-down"></i>
                        </a>
                        <div class="dropdown-menu">
                            <a href="../json/index.html">JSON 格式化</a>
                            <a href="../json/parser.html">JSON 格式校验</a>
                            <a href="../json/excel.html">JSON 转 Excel/CSV</a>
                            <a href="../json/jsonxml.html">JSON 与 XML 转换</a>
                            <a href="../json/editor.html">JSON 编辑器</a>
                        </div>
                    </div>
                    <div class="nav-item dropdown">
                        <a href="#" class="nav-link">
                            编码转换 <i class="fas fa-chevron-down"></i>
                        </a>
                        <div class="dropdown-menu">
                            <a href="../coding/base64.html">Base64 编码</a>
                            <a href="../coding/urlencoding.html">URL 编码</a>
                            <a href="../coding/md5.html">MD5 加密</a>
                            <a href="../coding/unicode.html">Unicode 转换</a>
                            <a href="../coding/hex_convert.html">进制转换</a>
                        </div>
                    </div>
                    <div class="nav-item dropdown">
                        <a href="#" class="nav-link">
                            文本工具 <i class="fas fa-chevron-down"></i>
                        </a>
                        <div class="dropdown-menu">
                            <a href="../txt/diff.html">文本对比</a>
                            <a href="../txt/replace.html">文本替换</a>
                            <a href="../txt/remove.html">空白行移除</a>
                            <a href="../txt/cn_trans.html">繁简体转换</a>
                        </div>
                    </div>
                    <div class="nav-item dropdown">
                        <a href="#" class="nav-link">
                            图片工具 <i class="fas fa-chevron-down"></i>
                        </a>
                        <div class="dropdown-menu">
                            <a href="../img/2svg.html">图片转 SVG</a>
                            <a href="../img/qr_code.html">二维码生成</a>
                            <a href="../img/barcode.html">条形码生成</a>
                        </div>
                    </div>
                </nav>
            </div>
            <div class="header-controls">
                <div class="theme-toggle">
                    <input type="checkbox" id="theme-switch" class="theme-switch">
                    <label for="theme-switch" class="theme-switch-label">
                        <i class="fas fa-sun"></i>
                        <i class="fas fa-moon"></i>
                        <span class="slider"></span>
                    </label>
                </div>
                <div class="share-button" id="share-button" title="分享给朋友">
                    <i class="fas fa-share-alt"></i>
                    <span>分享</span>
                </div>
            </div>
        </div>
    </header>
    <div class="container">
        <div id="privacy-notice" class="privacy-notice">
            <div class="privacy-notice-content">
                <i class="fas fa-shield-alt"></i>
                <p>安全提示：您的图片仅在本地浏览器中处理，不会上传到服务器，请放心使用！</p>
                <button id="close-notice" class="close-notice" title="关闭提示">
                    <i class="fas fa-times"></i>
                </button>
            </div>
        </div>
        
        <main>
            <div class="main-content">
                <div class="config-panel">
                    <h2><i class="fas fa-image"></i> 图片上传</h2>
                    
                    <div class="upload-area" id="upload-area">
                        <i class="fas fa-cloud-upload-alt"></i>
                        <p>点击或拖拽图片到此处上传</p>
                        <div class="file-info">支持 JPG、PNG、GIF、BMP 格式</div>
                        <input type="file" id="file-input" accept="image/*">
                    </div>
                    
                    <div class="preview-area" id="preview-area">
                        <h3>图片预览</h3>
                        <div class="preview-container">
                            <img id="preview-image" class="preview-image" alt="预览图片">
                            <div class="image-info" id="image-info"></div>
                        </div>
                    </div>
                    
                    <div class="config-options">
                        <h3>转换设置</h3>
                        <div class="config-group">
                            <label for="svg-width">SVG宽度 (px)</label>
                            <input type="number" id="svg-width" value="400" min="50" max="2000">
                        </div>
                        <div class="config-group">
                            <label for="svg-height">SVG高度 (px)</label>
                            <input type="number" id="svg-height" value="400" min="50" max="2000">
                        </div>
                        <div class="config-group">
                            <label for="preserve-ratio">保持宽高比</label>
                            <input type="checkbox" id="preserve-ratio" checked>
                        </div>
                    </div>
                </div>
                
                <div class="button-group">
                    <button id="convert-btn" class="btn btn-primary" disabled>
                        <i class="fas fa-magic"></i> 转换为SVG
                    </button>
                    <button id="download-btn" class="btn btn-success" style="display: none;">
                        <i class="fas fa-download"></i> 下载SVG
                    </button>
                    <button id="copy-btn" class="btn btn-success" style="display: none;">
                        <i class="fas fa-copy"></i> 复制SVG
                    </button>
                </div>
                
                <div class="loading" id="loading">
                    <i class="fas fa-spinner"></i>
                    <p>正在转换中，请稍候...</p>
                </div>
                
                <div class="result-panel" id="result-panel">
                    <h2><i class="fas fa-code"></i> SVG结果</h2>
                    <div class="svg-preview" id="svg-preview"></div>
                    <textarea id="svg-code" class="svg-code" readonly placeholder="SVG代码将在这里显示..."></textarea>
                </div>
            </div>
            
            <div class="sidebar">
                <div class="sidebar-section">
                    <h3><i class="fas fa-info-circle"></i> 使用说明</h3>
                    <p style="font-size: 14px; line-height: 1.6; color: var(--text-color);">
                        1. 点击上传区域或拖拽图片文件<br>
                        2. 支持JPG、PNG、GIF、BMP格式<br>
                        3. 设置SVG的宽度和高度<br>
                        4. 可选择是否保持原图宽高比<br>
                        5. 点击转换按钮生成SVG<br>
                        6. 预览结果并下载SVG文件
                    </p>
                </div>
                <div class="sidebar-section">
                    <h3><i class="fas fa-tools"></i> 其他工具</h3>
                    <ul class="tool-links">
                        <li><a href="../json/index.html"><i class="fas fa-code"></i> JSON 工具</a></li>
                        <li><a href="../coding/random_pwd.html"><i class="fas fa-key"></i> 随机密码生成器</a></li>
                        <li><a href="../coding/uuid.html"><i class="fas fa-key"></i> UUID 生成器</a></li>
                        <li><a href="../coding/base64.html"><i class="fas fa-lock"></i> Base64 编解码</a></li>
                        <li><a href="../coding/md5.html"><i class="fas fa-fingerprint"></i> MD5 加密</a></li>
                        <li><a href="../coding/timestamp.html"><i class="fas fa-clock"></i> 时间戳转换</a></li>
                        <li><a href="../coding/urlencoding.html"><i class="fas fa-link"></i> URL 编解码</a></li>
                        <li><a href="../coding/unicode.html"><i class="fas fa-globe"></i> Unicode 转换</a></li>
                        <li><a href="../coding/qr_code.html"><i class="fas fa-qrcode"></i> 二维码生成</a></li>
                        <li><a href="../coding/guid.html"><i class="fas fa-hashtag"></i> GUID 生成器</a></li>
                        <li><a href="../coding/regex.html"><i class="fas fa-search"></i> 正则表达式测试</a></li>
                        <li><a href="barcode.html"><i class="fas fa-barcode"></i> 条形码生成</a></li>
                    </ul>
                </div>
                
                <div class="sidebar-section">
                    <h3><i class="fas fa-ad"></i> 广告位</h3>
                    <div class="ad-placeholder">
                        <p>广告位招租</p>
                        <p>联系我们投放广告</p>
                    </div>
                </div>
            </div>
        </main>
    </div>
    <footer>
            <div class="footer-container">
                <div class="footer-main">
                    <div class="footer-section about-us">
                        <h3>关于我们</h3>
                        <p>我们提供一系列高效、便捷的在线工具，帮助开发者、非技术人员提高工作效率，解决日常开发中遇到的各种问题。</p>
                        <p>Build With <i class="fa-solid fa-heart" style="color: red;"></i> For SF.</p>
                    </div>
                    <div class="footer-section links">
                        <h3>工具导航</h3>
                        <div class="links-columns">
                            <ul>
                                <li><a href="../json/index.html">JSON 工具</a></li>
                                <li><a href="../img/index.html">图片处理</a></li>
                                <li><a href="#">开发工具</a></li>
                            </ul>
                            <ul>
                                <li><a href="../coding/index.html">编码转换</a></li>
                                <li><a href="../txt/index.html">文本工具</a></li>
                            </ul>
                        </div>
                    </div>
                    <div class="footer-section contact">
                        <h3>联系我们</h3>
                        <div class="social-icons">
                            <a href="#" title="GitHub"><i class="fab fa-github"></i></a>
                            <a href="#" title="Twitter"><i class="fab fa-twitter"></i></a>
                            <a href="#" title="WeChat"><i class="fab fa-weixin"></i></a>
                            <a href="mailto:example@example.com" title="Email"><i class="fas fa-envelope"></i></a>
                        </div>
                        <p>如有问题或建议，请随时联系我们</p>
                    </div>
                </div>
                <div class="footer-bottom">
                    <div class="footer-legal">
                        <a href="#">使用条款</a>
                        <a href="#">隐私政策</a>
                    </div>
                </div>
            </div>
        </footer>
    
    <div id="notification" class="notification"></div>
    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 获取DOM元素
            const themeSwitch = document.getElementById('theme-switch');
            const privacyNotice = document.getElementById('privacy-notice');
            const closeNoticeBtn = document.getElementById('close-notice');
            const shareButton = document.getElementById('share-button');
            const uploadArea = document.getElementById('upload-area');
            const fileInput = document.getElementById('file-input');
            const previewArea = document.getElementById('preview-area');
            const previewImage = document.getElementById('preview-image');
            const imageInfo = document.getElementById('image-info');
            const svgWidth = document.getElementById('svg-width');
            const svgHeight = document.getElementById('svg-height');
            const preserveRatio = document.getElementById('preserve-ratio');
            const convertBtn = document.getElementById('convert-btn');
            const downloadBtn = document.getElementById('download-btn');
            const copyBtn = document.getElementById('copy-btn');
            const loading = document.getElementById('loading');
            const resultPanel = document.getElementById('result-panel');
            const svgPreview = document.getElementById('svg-preview');
            const svgCode = document.getElementById('svg-code');
            const notification = document.getElementById('notification');
            
            let currentFile = null;
            let currentSvgData = null;
            
            // 检查本地存储中的主题设置
            if (localStorage.getItem('theme') === 'dark') {
                document.documentElement.setAttribute('data-theme', 'dark');
                themeSwitch.checked = true;
            }
            
            // 主题切换功能
            themeSwitch.addEventListener('change', function() {
                if (this.checked) {
                    document.documentElement.setAttribute('data-theme', 'dark');
                    localStorage.setItem('theme', 'dark');
                } else {
                    document.documentElement.removeAttribute('data-theme');
                    localStorage.setItem('theme', 'light');
                }
            });
            
            // 关闭隐私提示
            closeNoticeBtn.addEventListener('click', function() {
                privacyNotice.style.display = 'none';
                localStorage.setItem('privacy-notice-closed', 'true');
            });
            
            // 检查是否已关闭隐私提示
            if (localStorage.getItem('privacy-notice-closed') === 'true') {
                privacyNotice.style.display = 'none';
            }
            
            // 分享功能
            shareButton.addEventListener('click', function() {
                if (navigator.share) {
                    navigator.share({
                        title: '图片转SVG工具',
                        text: '一个实用的在线图片转SVG工具',
                        url: window.location.href
                    });
                } else {
                    navigator.clipboard.writeText(window.location.href).then(() => {
                        showNotification('链接已复制到剪贴板！');
                    }).catch(() => {
                        showNotification('分享失败，请手动复制链接！', true);
                    });
                }
            });
            
            // 显示通知
            function showNotification(message, isError = false) {
                notification.textContent = message;
                notification.className = 'notification show' + (isError ? ' error' : '');
                setTimeout(() => {
                    notification.classList.remove('show');
                }, 3000);
            }
            
            // 文件上传处理
            uploadArea.addEventListener('click', () => fileInput.click());
            
            uploadArea.addEventListener('dragover', (e) => {
                e.preventDefault();
                uploadArea.classList.add('dragover');
            });
            
            uploadArea.addEventListener('dragleave', () => {
                uploadArea.classList.remove('dragover');
            });
            
            uploadArea.addEventListener('drop', (e) => {
                e.preventDefault();
                uploadArea.classList.remove('dragover');
                const files = e.dataTransfer.files;
                if (files.length > 0) {
                    handleFile(files[0]);
                }
            });
            
            fileInput.addEventListener('change', (e) => {
                if (e.target.files.length > 0) {
                    handleFile(e.target.files[0]);
                }
            });
            
            // 处理文件
            function handleFile(file) {
                if (!file.type.startsWith('image/')) {
                    showNotification('请选择有效的图片文件！', true);
                    return;
                }
                
                currentFile = file;
                const reader = new FileReader();
                
                reader.onload = function(e) {
                    previewImage.src = e.target.result;
                    previewImage.onload = function() {
                        const width = this.naturalWidth;
                        const height = this.naturalHeight;
                        const size = (file.size / 1024).toFixed(2);
                        
                        imageInfo.innerHTML = `
                            <strong>文件名：</strong>${file.name}<br>
                            <strong>尺寸：</strong>${width} × ${height} px<br>
                            <strong>大小：</strong>${size} KB
                        `;
                        
                        // 自动设置SVG尺寸为原图尺寸
                        svgWidth.value = width;
                        svgHeight.value = height;
                        
                        previewArea.style.display = 'block';
                        convertBtn.disabled = false;
                        showNotification('图片上传成功！');
                    };
                };
                
                reader.readAsDataURL(file);
            }
            
            // 保持宽高比
            preserveRatio.addEventListener('change', function() {
                if (this.checked && previewImage.src) {
                    const ratio = previewImage.naturalWidth / previewImage.naturalHeight;
                    svgHeight.value = Math.round(svgWidth.value / ratio);
                }
            });
            
            svgWidth.addEventListener('input', function() {
                if (preserveRatio.checked && previewImage.src) {
                    const ratio = previewImage.naturalWidth / previewImage.naturalHeight;
                    svgHeight.value = Math.round(this.value / ratio);
                }
            });
            
            svgHeight.addEventListener('input', function() {
                if (preserveRatio.checked && previewImage.src) {
                    const ratio = previewImage.naturalWidth / previewImage.naturalHeight;
                    svgWidth.value = Math.round(this.value * ratio);
                }
            });
            
            // 转换为SVG
            convertBtn.addEventListener('click', function() {
                if (!currentFile) {
                    showNotification('请先上传图片！', true);
                    return;
                }
                
                loading.style.display = 'block';
                resultPanel.style.display = 'none';
                
                // 模拟转换过程
                setTimeout(() => {
                    convertToSvg();
                }, 1000);
            });
            
            // 转换为SVG函数
            function convertToSvg() {
                const canvas = document.createElement('canvas');
                const ctx = canvas.getContext('2d');
                const img = new Image();
                
                img.onload = function() {
                    const targetWidth = parseInt(svgWidth.value);
                    const targetHeight = parseInt(svgHeight.value);
                    
                    canvas.width = targetWidth;
                    canvas.height = targetHeight;
                    
                    // 绘制图片到canvas
                    ctx.drawImage(img, 0, 0, targetWidth, targetHeight);
                    
                    // 获取图片数据
                    const imageData = canvas.toDataURL('image/png');
                    
                    // 创建SVG
                    const svgContent = `<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="${targetWidth}" height="${targetHeight}" viewBox="0 0 ${targetWidth} ${targetHeight}">
  <image x="0" y="0" width="${targetWidth}" height="${targetHeight}" xlink:href="${imageData}"/>
</svg>`;
                    
                    currentSvgData = svgContent;
                    
                    // 显示结果
                    svgCode.value = svgContent;
                    svgPreview.innerHTML = svgContent;
                    
                    loading.style.display = 'none';
                    resultPanel.style.display = 'block';
                    downloadBtn.style.display = 'inline-flex';
                    copyBtn.style.display = 'inline-flex';
                    
                    showNotification('SVG转换完成！');
                };
                
                img.src = previewImage.src;
            }
            
            // 下载SVG
            downloadBtn.addEventListener('click', function() {
                if (!currentSvgData) {
                    showNotification('没有可下载的SVG文件！', true);
                    return;
                }
                
                const blob = new Blob([currentSvgData], { type: 'image/svg+xml' });
                const url = URL.createObjectURL(blob);
                const a = document.createElement('a');
                a.href = url;
                a.download = (currentFile ? currentFile.name.replace(/\.[^/.]+$/, '') : 'image') + '.svg';
                document.body.appendChild(a);
                a.click();
                document.body.removeChild(a);
                URL.revokeObjectURL(url);
                
                showNotification('SVG文件下载成功！');
            });
            
            // 复制SVG
            copyBtn.addEventListener('click', function() {
                if (!currentSvgData) {
                    showNotification('没有可复制的SVG内容！', true);
                    return;
                }
                
                navigator.clipboard.writeText(currentSvgData).then(() => {
                    showNotification('SVG内容已复制到剪贴板！');
                }).catch(() => {
                    // 降级方案：使用传统方法复制
                    const textArea = document.createElement('textarea');
                    textArea.value = currentSvgData;
                    document.body.appendChild(textArea);
                    textArea.select();
                    try {
                        document.execCommand('copy');
                        showNotification('SVG内容已复制到剪贴板！');
                    } catch (err) {
                        showNotification('复制失败，请手动复制！', true);
                    }
                    document.body.removeChild(textArea);
                });
            });
            
            // 键盘快捷键
            document.addEventListener('keydown', function(e) {
                if (e.ctrlKey || e.metaKey) {
                    switch(e.key) {
                        case 'o':
                            e.preventDefault();
                            fileInput.click();
                            break;
                        case 'Enter':
                            if (!convertBtn.disabled) {
                                e.preventDefault();
                                convertBtn.click();
                            }
                            break;
                        case 's':
                            if (currentSvgData) {
                                e.preventDefault();
                                downloadBtn.click();
                            }
                            break;
                        case 'c':
                            if (currentSvgData) {
                                e.preventDefault();
                                copyBtn.click();
                            }
                            break;
                    }
                }
            });
        });
    </script>
</body>
</html>